package com.hiof.moraa.server.controller.restfulservice;

import com.hiof.moraa.server.dao.AthleteLiveLocationDAO;
import com.hiof.moraa.server.service.LiveLocationService;
import com.hiof.moraa.server.service.TeamMemberLocationService;
import com.hiof.moraa.server.service.model.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/restfulservice")
public class TeamMemberLocationController {

    @Autowired
    TeamMemberLocationService teamMemberLocationService;
    @Autowired
    LiveLocationService athleteLiveLocationService;

    @RequestMapping(value = "/supportteammemberlocation", method = RequestMethod.POST)
    @ResponseBody
    public TeamMemberLocationPacket supportLocationServiceMethod(
            @RequestParam("athleteId") int athleteId) throws Exception {
        return teamMemberLocationService.getSupportsLocation(athleteId);
    }

    @RequestMapping(value = "/athleteLatestLocation", method = RequestMethod.POST)
    @ResponseBody
    public GeoPoint getLatestLocationOfAthlete(
            @RequestParam("athleteId") int athleteId) throws Exception{
        return athleteLiveLocationService.getLatestLocation(athleteId);
    }

}
